Method and apparatus for using a shared library mechanism to facilitate sharing of metadata

ABSTRACT

One embodiment of the present invention provides a system that uses a shared library to facilitate sharing objects containing metadata. During operation, the system receives identifiers for a set of objects to be included in the shared library. Next, the system generates a shared library containing the set of objects. In doing so, the system configures a symbol table within the shared library to include an identifier for each object. The system then installs the shared library in a file system, and configures the file system so that the shared library file can be accessed through a set of symbolic names, wherein each object is associated with a different symbolic name. This allows each object in the shared library to be referenced through its own symbolic name. Note that the present invention uses the shared library mechanism in a manner which differs from its typical use (sharing compiled, executable code). In order to avoid generating a shared library for each metadata object, the present invention places many such items together in one shared library. The names of these metadata objects are subsequently used as symbolic names of the file containing the shared library.

RELATED APPLICATION

[0001] This application hereby claims priority under 35 U.S.C. §119 to U.S. Provisional Patent Application No. 60/332,924, filed on Nov. 14, 2001, entitled “Sharing Meta-Data Across Instances of a Language Run-Time System,” by inventors Grzegorz J. Czajkowski and Laurent P. Daynes.

BACKGROUND

[0002] 1. Field of the Invention

[0003] The present invention relates to operating systems for computers. More specifically, the present invention relates to a method and an apparatus that uses a shared library mechanism to facilitate sharing metadata, such as classes or compiled methods, between multiple instances of a language run-time system.

[0004] 2. Related Art

[0005] It is often advantageous to share metadata, such as class files or dynamically compiled code, across multiple instances of a runtime system of a programming language, such as the Java Virtual Machine (JVM™). (The terms “Sun Microsystems”, “Java”, “Java virtual machine” and “JVM” are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.)

[0006] Sharing of metadata across multiple instances of a language runtime system can be accomplished by storing the metadata in a shared memory area. However, unless the metadata is read-only, such sharing means that there will exist periods of time when the shared memory area will be accessible for writing by the sharing processes. In some situations this does not create a problem. However, a bug in one of the instances or in a user-supplied native library may lead to uncontrolled writing in the shared memory area. This may cause the shared memory area to be corrupted for all processes, not just for the process that actually corrupted the shared memory area.

[0007] Another problem with using shared memory is that updates to the shared memory area have to be guarded by a concurrency control primitive, such as a monitor or a semaphore. If a process making an update (e.g., adding another piece of metadata) unexpectedly terminates during the update, the system must ensure that the relevant concurrency control objects are released in order to avoid preventing other processes from using the shared memory area.

[0008] Despite these challenges, sharing of metadata remains attractive because of its potential to decrease the memory footprint of virtual machines and to factor out costs related to on-demand class loading (e.g., parsing, verification, dynamic link resolution) and to architecture neutrality of class files (e.g., runtime quickening of interpreted code and runtime compilations).

[0009] What is needed is method and an apparatus that facilitates sharing of metadata between multiple virtual machines and/or processes in a manner that efficiently deals with the above-described challenges.

SUMMARY

[0010] One embodiment of the present invention provides a system that uses a shared library mechanism to facilitate sharing objects containing metadata. During operation, the system receives identifiers for a set of objects to be included in a shared library. Next, the system generates a shared library containing the set of objects. In doing so, the system configures a symbol table within the shared library to include an identifier for each object. The system then installs the shared library in a file system, and configures the file system so that the shared library file can be accessed through a set of symbolic names, wherein each object is associated with a different symbolic name. This allows each object in the shared library to be referenced through its own symbolic name.

[0011] Note that the present invention uses the shared library mechanism in a manner which differs from its typical use (sharing compiled, executable code). In order to avoid generating a shared library for each metadata object, the present invention places many such items together in one shared library. The names of these metadata objects are subsequently used as symbolic names of the file containing the shared library. In this way, fetching a metadata object “Obj” can be accomplished simply by opening shared library named Obj.

[0012] This use of shared libraries depends on the following property of shared libraries (present in several commercially available operating systems): loading the same shared library via different symbolic names by a process results in loading it only once by this process: the first load actually loads the library, and subsequent loads return the handle to the previously loaded library.

[0013] In a variation on the above embodiment, generating the shared library involves placing ready-only portions of objects in a read-only region of the shared library, and placing writeable portions of objects in a writeable region of the shared library.

[0014] In a variation on this embodiment, the system enforces a copy-on-write policy by ensuring that a write operation to a data item in the writeable region of the shared library is restricted to a local copy of the data item in the local address space of a process that issued the write operation.

[0015] In a variation on this embodiment, an object in the set of objects defines a class containing methods to be shared between instances of a language run-time system.

[0016] In a variation on this embodiment, an object in the set of objects contains dynamically compiled code to be shared between instances of a language run-time system.

[0017] In a variation on this embodiment, the system accesses a target object in the shared library by accessing the shared library through a symbolic name associated with the target object, and then looking up the target object in the symbol table of the shared library to determine a location of the target object within the shared library.

[0018] In a variation on this embodiment, a symbolic name for an object can be inferred from the identifier for the object.

BRIEF DESCRIPTION OF THE FIGURES

[0019]FIG. 1 illustrates a computer system in accordance with an embodiment of the present invention.

[0020]FIG. 2 illustrates a shared library in accordance with an embodiment of the present invention.

[0021]FIG. 3A is a flow chart illustrating how a shared library can be created in accordance with an embodiment of the present invention.

[0022]FIG. 3B is a flow chart illustrating how a shared library is loaded or created in accordance with another embodiment of the present invention.

[0023]FIG. 4 is a flow chart illustrating the process of generating and configuring a shared library in accordance with an embodiment of the present invention.

[0024]FIG. 5 is a flow chart illustrating the process of accessing an object within a shared library in accordance with an embodiment of the present invention.

DETAILED DESCRIPTION

[0025] The following description is presented to enable any person skilled in the art to make and use the invention, and is provided in the context of a particular application and its requirements. Various modifications to the disclosed embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other embodiments and applications without departing from the spirit and scope of the present invention. Thus, the present invention is not limited to the embodiments shown, but is to be accorded the widest scope consistent with the principles and features disclosed herein.

[0026] The data structures and code described in this detailed description are typically stored on a computer readable storage medium, which may be any device or medium that can store code and/or data for use by a computer system. This includes, but is not limited to, magnetic and optical storage devices such as disk drives, magnetic tape, CDs (compact discs) and DVDs (digital versatile discs or digital video discs), and computer instruction signals embodied in a transmission medium (with or without a carrier wave upon which the signals are modulated). For example, the transmission medium may include a communications network, such as the Internet.

[0027] Computer System

[0028]FIG. 1 illustrates a computer system 100 in accordance with an embodiment of the present invention. Computer system 100 can generally include any type of computer system that can support multiple processes, including, but not limited to, a computer system based on a microprocessor, a mainframe computer, a digital signal processor, a portable computing device, a personal organizer, a device controller, and a computational engine within an appliance. Computer system 100 can also include any type of computer system that supports communications between parallel processors, such as a multiprocessor system or certain types of distributed computer systems.

[0029] Computer system 100 contains an operating system 101, which supports a number of processes 102-104 that can share metadata located in shared library 116. Each of these processes 102-104 operates within its own virtual address space. In particular, process 102 operates on address space 112, process 103 operates on address space 113, and process 104 operates on address space 114. In one embodiment of the present invention, processes 102-104 execute separate instances of a language runtime system, such as the Java Virtual Machine.

[0030] Operating system 101 also supports a shared library mechanism. Each shared library may include a read-only region 140 as well as a writeable region 141. Shared library 116 implements a copy-on-write policy. This means for example, if process 102 attempts to write to a page in writeable region 141 of shared library 116, a local copy of the page is created in the local address space 112 for process 102. The write operation is then applied only to the local copy of the page, and does not propagate to other versions of the page. Hence, shared library 116 ensures that read-only region 140 cannot be corrupted (because it cannot be written to) and that erroneous writes to writeable region 141 will only corrupt corresponding memory in the address space of the process that issued the writes.

[0031] Regions of shared library 116 are mapped into local address spaces 112-114. More specifically, read-only region 140 of shared library 116 is mapped into read-only region 122 of local address space 112, and writeable region 141 of shared library 116 is mapped into writeable region 132 of local address space 112. Similarly, read-only region 140 of shared library 116 is mapped into read-only region 123 of local address space 112, and writeable region 141 of shared library 116 is mapped into writeable region 133 of local address space 112. Finally, read-only region 140 of shared library 116 is mapped into read-only region 124 of local address space 112, and writeable region 141 of shared library 116 is mapped into writeable region 134 of local address space 112.

[0032] Shared Library

[0033]FIG. 2 illustrates the structure of shared library 116 in accordance with an embodiment of the present invention. Shared library 116 contains a number of objects C1, C2, C3, which, for example, can define Java classes. Each of these classes has a read-only portion, which is stored in read-only region 140 of shared library 116, and a writeable portion, which is stored writeable region 141 of shared library 116. More specifically, objects C1, C2 and C3 have read-only portions C1 ^(R), C2 ^(R) and C3 ^(R), which are stored in read-only region 140, as well as writeable portions C1 ^(W), C2 ^(W) and C3 ^(W), which are stored in writeable region 141.

[0034] Shared library 116 also includes a symbol table 202, which functions as an index to facilitate looking up the read-only and writeable portions of objects within shared library 116.

[0035] Shared library 116 can be referenced through many different names (via symbolic links) to facilitate easily referencing a library containing the required metadata. For example, if classes C1, C2 and C3 are stored in shared library 116, shared library 116 can be accessed through corresponding symbolic names: LibC1, LibC2 and LibC3.

[0036] Note that modem operating systems typically have the following property, which the present invention takes advantage of: loading the same shared library via different symbolic names by a process results in loading it only once by this process: the first load actually loads the library, and subsequent loads return the handle to the previously loaded library. This is important because it avoids having to maintain a mapping from metadata object names to library names; such a mapping can be costly in terms of time and/or space.

[0037] In order to use multiple symbolic names to access shared library 116, it is advantageous for the implementation of shared library 116 to have the following property: after shared library 116 has been loaded by a process, subsequent requests to load shared library 116 under different symbolic names by the same process result in returning a handle to the originally loaded shared library. Otherwise, another naming scheme (not using symbolic links) may have to be used to store multiple metadata objects in the same shared library.

[0038] Note that storing multiple metadata objects in the same shared library avoids internal fragmentation that arises when page size is relatively large compared to a typical size of an instance of a metadata object.

[0039] Process of Loading a Shared Library

[0040]FIG. 3A is a flow chart illustrating how a shared library can be created in accordance with an embodiment of the present invention. In this embodiment, a metadata object, M, is generated off-line prior to its use, for example during a compilation stage (step 302). Metadata object M is then encoded into shared library 116 (step 304). Note that this encoding process computes both a read-only portion, M_(R), and a writeable portion, M_(W), of the metadata object M. During execution of a runtime system, a request to use metadata object M is satisfied by loading shared library 116 into the runtime system (step 306).

[0041] Another way to use shared library 116 is illustrated in the flow chart that appears in FIG. 3B. First, an instance of a run-time system attempts to load shared library 116 from a cache containing shared libraries (step 312). For example, the cache can be a directory in a file system containing all the shared libraries that contain metadata. If the attempt is successful, shared library 116 is loaded and the process is complete.

[0042] Otherwise, if the attempt is not successful, the instance of the run-time system generates shared library 116 (step 316) and then stores shared library 116 into the cache (step 318).

[0043] Shared Library Generation

[0044]FIG. 4 is a flow chart illustrating the process of generating and configuring a shared library in accordance with an embodiment of the present invention. This process can take place either offline prior to the library's use, or alternatively at runtime.

[0045] The system starts by receiving identifiers for a list of objects to be included in the shared library (step 402). Next, the system generates a shared library 116 containing the objects (step 404). During this process, the system places read-only portions of objects in the read-only region 140 of shared library 116, and places writeable portions of objects in the writeable region 141 of shared library 116.

[0046] Next, the system configures symbol table 202 in shared library 116 to include identifiers for the objects (step 406). This facilitates looking up locations of the objects within shared library 116.

[0047] Next, the system installs shared library 116 into the file system (step 408). The system also configures the file system so that shared library 116 can be accessed through a set of symbolic names LibC1, LibC2 and LibC3 (step 410). Note that each object is associated with a different symbolic name, which can be inferred from the name of the object. For example, the shared library 116 containing object C1 can be reference through the symbolic name LibC1 (see FIG. 2). Note that this technique uses the existing symbolic linking mechanism of a file system to facilitate referencing a shared library containing an object without having to keep track of which shared library contains the object.

[0048] Process of Accessing an Object from a Shared Library

[0049]FIG. 5 is a flow chart illustrating the process of accessing an object within a shared library 116 in accordance with an embodiment of the present invention. In order to access an object, the system first accesses the shared library containing the object through the symbolic name associated with the object (step 502). For example, in order to access class C2, the system first accesses shared library 116 through an associated symbolic link LibC2 that points to shared library 116 (see FIG. 2). Next, the system looks up the object in the symbol table for the shared library (step 504). For example, the system can lookup class C2 in symbol table 202 in shared library 116 to return the locations for read-only portion, C2 ^(R), and the writeable portion, C2 ^(W), of class C2 (see FIG. 2).

[0050] Note that the above-described technique of using a shared library to store metadata provides the benefits of using a separate custom-managed shared memory area for sharing metadata, since physical memory containing parts of shared libraries are shared among all processes which have loaded a given shared library, thus lowering memory footprint.

[0051] Moreover, the copy-on-write mechanism of the shared library eliminates the problem of memory corruption problems between processes.

[0052] Furthermore, the above-described use of multiple symbolic links simplifies the process of referencing a shared library containing an object.

[0053] The foregoing descriptions of embodiments of the present invention have been presented only for purposes of illustration and description. They are not intended to be exhaustive or to limit the present invention to the forms disclosed. Accordingly, many modifications and variations will be apparent to practitioners skilled in the art. Additionally, the above disclosure is not intended to limit the present invention. The scope of the present invention is defined by the appended claims. 

What is claimed is:
 1. A method that uses a shared library mechanism to facilitate sharing objects, comprising: receiving identifiers for a set of objects to be included in a shared library; generating the shared library containing the set of objects; configuring a symbol table within the shared library to include an identifier for each object in the set of objects; installing the shared library in a file system; configuring the file system so that the shared library can be accessed through a set of symbolic names; wherein each object in the shared library is associated with a different symbolic name, so that each object can be referenced through its own symbolic name.
 2. The method of claim 1, wherein generating the shared library involves: placing ready-only portions of objects in a read-only region of the shared library; and placing writeable portions of objects in a writeable region of the shared library.
 3. The method of claim 2, further comprising enforcing a copy-on-write policy by ensuring that a write operation to a data item in the writeable region of the shared library is restricted to a local copy of the data item in a local address space of a process that issued the write operation.
 4. The method of claim 1, wherein an object in the set of objects defines a class containing methods to be shared between instances of a language run-time system.
 5. The method of claim 1, wherein an object in the set of objects contains dynamically compiled code to be shared between instances of a language run-time system.
 6. The method of claim 1, further comprising accessing a target object in the shared library by: accessing the shared library through a symbolic name associated with the target object; and looking up the target object in the symbol table of the shared library to determine a location of the target object within the shared library.
 7. The method of claim 1, wherein a symbolic name for an object can be inferred from the identifier for the object.
 8. The method of claim 1, wherein configuring the file system so that the shared library can be accessed through the set of symbolic names involves loading the shared library via different symbolic names in the set of symbolic names so that a first load actually loads the shared library, and subsequent loads return a handle to the previously loaded library.
 9. A computer-readable storage medium storing instructions that when executed by a computer cause the computer to perform a method that uses a shared library mechanism to facilitate sharing objects, the method comprising: receiving identifiers for a set of objects to be included in the shared library; generating a shared library containing the set of objects; configuring a symbol table within the shared library to include an identifier for each object in the set of objects; installing the shared library in a file system; configuring the file system so that the shared library can be accessed through a set of symbolic names; wherein each object in the shared library is associated with a different symbolic name, so that each object can be referenced through its own symbolic name.
 10. The computer-readable storage medium of claim 9, wherein generating the shared library involves: placing ready-only portions of objects in a read-only region of the shared library; and placing writeable portions of objects in a writeable region of the shared library.
 11. The computer-readable storage medium of claim 10, wherein the method further comprises enforcing a copy-on-write policy by ensuring that a write operation to a data item in the writeable region of the shared library is restricted to a local copy of the data item in a local address space of a process that issued the write operation.
 12. The computer-readable storage medium of claim 9, wherein an object in the set of objects defines a class containing methods to be shared between instances of a language run-time system.
 13. The computer-readable storage medium of claim 9, wherein an object in the set of objects contains dynamically compiled code to be shared between instances of a language run-time system.
 14. The computer-readable storage medium of claim 9, wherein the method further comprises accessing a target object in the shared library by: accessing the shared library through a symbolic name associated with the target object; and looking up the target object in the symbol table of the shared library to determine a location of the target object within the shared library.
 15. The computer-readable storage medium of claim 9, wherein a symbolic name for an object can be inferred from the identifier for the object.
 16. The computer-readable storage medium of claim 9, wherein configuring the file system so that the shared library can be accessed through the set of symbolic names involves loading the shared library via different symbolic names in the set of symbolic names so that a first load actually loads the shared library, and subsequent loads return a handle to the previously loaded library.
 17. An apparatus that uses a shared library mechanism to facilitate sharing objects, comprising: a library generation mechanism that is configured to generate a shared library, wherein the shared library contains a set of objects; wherein the library generation mechanism is configured to populate a symbol table within the shared library to include an identifier for each object in the set of objects; and a library installation mechanism that is configured to install the shared library in a file system; wherein the library installation mechanism is configured to update the file system so that the shared library can be accessed through a set of symbolic names; wherein each object in the shared library is associated with a different symbolic name, so that each object can be referenced through its own symbolic name.
 18. The apparatus of claim 17, wherein the library generation mechanism is configured to: place ready-only portions of objects in a read-only region of the shared library; and to place writeable portions of objects in a writeable region of the shared library.
 19. The apparatus of claim 18, further comprising a copy-on-write mechanism, which ensures that a write operation to a data item in the writeable region of the shared library is restricted to a local copy of the data item in a local address space of a process that issued the write operation.
 20. The apparatus of claim 17, wherein an object in the set of objects defines a class containing methods to be shared between instances of a language run-time system.
 21. The apparatus of claim 17, wherein an object in the set of objects contains dynamically compiled code to be shared between instances of a language run-time system.
 22. The apparatus of claim 17, further comprising a library access mechanism that is configured to: accessing a target object in the shared library through a symbolic name associated with the target object; and to look up the target object in the symbol table of the shared library to determine a location of the target object within the shared library.
 23. The apparatus of claim 17, wherein a symbolic name for an object can be inferred from the identifier for the object.
 24. The apparatus of claim 17, wherein the library installation mechanism is configured to load the shared library via different symbolic names in the set of symbolic names so that a first load actually loads the shared library, and subsequent loads return a handle to the previously loaded library.
 25. A computer system that uses a shared library to facilitate sharing objects, comprising: a file system; the shared library with the file system that contains a set of objects; and a symbol table within the shared library that includes an identifier for each object in the set of objects; wherein the file system is configured so that the shared library can be accessed through a set of symbolic names; wherein each object in the shared library is associated with a different symbolic name, so that each object can be referenced through its own symbolic name.
 26. The computer system of claim 25, wherein shared library includes a read only section containing ready-only portions of objects; and a writeable section containing writeable portions of objects.
 27. The computer system of claim 26, wherein the shared library includes a copy-on-write mechanism, which ensures that a write operation to a data item in the writeable section of the shared library is restricted to a local copy of the data item in a local address space of a process that issued the write operation.
 28. The computer system of claim 25, wherein an object in the set of objects defines a class containing methods to be shared between instances of a language run-time system.
 29. The computer system of claim 25, wherein an object in the set of objects contains dynamically compiled code to be shared between instances of a language run-time system.
 30. The computer system of claim 25, wherein a symbolic name for an object can be inferred from the identifier for the object. 